package com.three.Controller;
import com.github.pagehelper.PageInfo;
import com.three.Pojo.Teacher;
import com.three.Service.ITeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    private ITeacherService teacherService;

    @RequestMapping("/toteacher.do")
    public String toteacher(ModelMap map, String teacherName,
                            @RequestParam(defaultValue = "1") Integer pageNum,
                            @RequestParam(defaultValue = "5") Integer pageSize){
        PageInfo<Teacher> pagelist=teacherService.findlist(pageNum,pageSize,teacherName);
        map.addAttribute("pagelist",pagelist);
        map.addAttribute("teacherName",teacherName);
        return "teacher";
    }

    @RequestMapping("/toadd.do")
    public String toadd(){
        return "teacherAdd";
    }

    @RequestMapping("/addsave.do")
    public String addsave(Teacher teacher){
        teacherService.addsave(teacher);
        return "redirect:/teacher/toteacher.do";
    }
    @RequestMapping("/promodify.do")
    public String promodify(Integer Id,ModelMap map){
        Teacher teacher=teacherService.findByid(Id);
        map.addAttribute("teacher",teacher);
        return "teacherUpdate";
    }
    @RequestMapping("/updatesave.do")
    public String updatesave(Teacher teacher){
        teacherService.updatesave(teacher);
        return "redirect:/teacher/toteacher.do";
    }

    @RequestMapping("/delete.do")
    public String delete(Integer Id){
        teacherService.delete(Id);
        return "redirect:/teacher/toteacher.do";
    }

}
